package main

import (
	"fmt"
	"time"
)

func main() {
	defer func() {
		if err := recover(); err != nil {
			fmt.Println("捕获异常：", err)
		}
	}()

	bigMap := make(map[int]int)

	for i := 0; i < 100; i++ {
		go func() {
			bigMap[i] = i * 4
		}()
	}
	time.Sleep(5 * time.Second)
}

// map的并发读写产生的panic不会被捕捉到，因为它会触发runtime.throw(),而throw()会调用fatathrow()，对于fatathrow()的解释如下：
// fatalthrow implements an unrecoverable runtime throw. It freezes the
// system, prints stack traces starting from its caller, and terminates the
// process.
// 意思为fatalthrow实现了一个不可恢复的throw，它会冻结系统，打印堆栈信息，并且终止程序。
